<?php
include "classes/security.class.php";

$action = $_GET["action"];
if(!$action){
	$action = $_POST["action"];
}

switch ($action){
	case "login":
		login($_POST["user"], $_POST["pass"]);
		break;
	case "logout":
		logout();
		break;
}

function login($u,$p){
	
	$db = new db_functions();
	$sql = "SELECT * FROM users WHERE username='$u' AND password=PASSWORD('$p')";
	
	$res = $db->getRow($sql);
	if($res[0]){
		setcookie("ypu",$res[0]);
	}
	echo "index.php";
}

function logout(){
	if (isset($_COOKIE['ypu'])){
		setcookie ("ypu", "", time()-60*60*24*100);
	}

	echo "index.php";
}

?>